<template>
  <div>
    <el-container>
      <el-header class="homeHeader">
        <div class="title">瓜子二手车</div>
        <el-dropdown class="userInfo" @command="commandHandler">
        <span class="el-dropdown-link" >
      管理员<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="userinfo">个人中心</el-dropdown-item>
            <el-dropdown-item command="setting">设置</el-dropdown-item>
            <el-dropdown-item command="logout">退出登陆</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu router unique-opend>
            <el-submenu :index="index+''" v-for="(item,index) in routes" :key="index" v-if="!item.hidden">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{item.name}}</span>
            </template>
              <el-menu-item :index="children.path" v-for="(children,index) in item.children">{{children.name}}</el-menu-item>
              </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <el-breadcrumb v-if="this.$router.currentRoute.path!='/home'" separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home'}">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{this.$router.currentRoute.name}}</el-breadcrumb-item>
          </el-breadcrumb>
          <div class="homeWelcome" v-if="this.$router.currentRoute.path=='/home'">

          </div>
          <router-view class="homeRouterView"/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>

export default {
  name: 'Home',
  computed:{
     routes(){
       return this.$store.state.routes;
     }
  },
  methods:{
    commandHandler(command){
     if (command=='logout') {
       this.$confirm('此操作将注销登陆, 是否继续?', '提示', {
         confirmButtonText: '确定',
         cancelButtonText: '取消',
         type: 'warning'
       }).then(() => {
         this.$router.replace('/')
       }).catch(() => {
         this.$message({
           type: 'info',
           message: '已取消登陆'
         });
       });
      }
    }
  }
}
</script>


<style>
  .homeHeader{
    background: #99a9bf;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    box-sizing: border-box;
  }

  .homeHeader .title{
    font-size: 38px;
    font-family: 楷体;
    color: white;
  }

  .homeRouterView{
    margin-top: 18px;
  }


</style>